package com.ljm.boot.helloword.letCode;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class Test {
    public static void main(String[] args) {
       // test03();
        test04(new int[]{1,2,7,9,0,0,0},4,new int[]{4,6,7},3);

    }

    public static void test1(int a,int b,int c){
        //test2(1,2,4);
        for (int i=c ;i>=0;i--) {
            int d= a*i+b*(c-i);
            System.out.println(d+":"+a+"*"+i+"+"+b+"*"+(c-i));
        }

    }

    public static void test2() {
        Scanner in = new Scanner(System.in);
        String numbers  = in.nextLine();
        String[] arr = numbers.split(",");
        int x = Integer.parseInt(arr[0]);
        int y = Integer.parseInt(arr[1]);
        int x1 = Integer.parseInt(arr[2]);
        int y1 = Integer.parseInt(arr[3]);
        int x2 = Integer.parseInt(arr[4]);
        int y2 = Integer.parseInt(arr[5]);

        int[][] xy = new int[x][y];
        for(int i=0;i<x;i++){
            for(int j=0 ; j<y ;j++){
                // System.out.println(i +"-"+ j);
                xy[i][j] = 0;
            }
        }
        xy[x1][y1] = 1;
        xy[x2][y2] = 1;
        int count  = x * y -2;
        ArrayList<int[]> intArr = new ArrayList<int[]>();
        intArr.add(new int[]{x1,y1});
        intArr.add(new int[]{x2,y2});
        int[][] a = {{1,0},{-1,0},{0,1},{0,-1}};
        int s = 0;
        while (intArr.size()>0&&count>0){
            ArrayList<int[]> intArr2 = new ArrayList<int[]>();
            for (int[] arr2: intArr) {
                int xx1 = arr2[0];
                int yy1 = arr2[1];
                for (int[] num : a){
                    int xx2 = xx1+num[0];
                    int yy2 = yy1+num[1];
                    if(xx2>=0&&xx2<x&&yy2>=0&&yy2<y&&xy[xx2][yy2]==0){
                        xy[xx2][yy2]=1;
                        intArr2.add(new int[]{xx2,yy2});
                        count--;
                    }
                }
            }
            intArr = intArr2;
            s++;
        }
        System.out.println(s);
    }

    public static  void test03(){
        int[] nums =  new int[]{1,2,59,4,89,2,5656,10,9,20};
        for (int i=0;i< nums.length;i++){
            int temp = 0;
            for (int j=1+i;j< nums.length;j++){
                if(nums[i]>nums[j]){
                    temp = nums[i];
                    nums[i] = nums[j];
                    nums[j] = temp;
                }
                System.out.println(i+Arrays.toString(nums));
            }

        }
        System.out.println(Arrays.toString(nums));

    }

    public static  int[] test04(int[] nums,int m,int[] nums2,int n){
        int k = m+n;
        if(nums2.length==0){
           return  nums;
        }
        int index1 = m-1;
        int index2 = n-1;
        for (int i=k-1;i >=0;i--){
            if(index1<0||index2<0){
                if(index1>index2){
                    nums[i]  = nums[index1];
                    index1= index1-1;
                }else if(index1<index2){
                    nums[i]  = nums[index2];
                    index2= index2-1;
                }
            }else{
                if(nums[index1]>=nums2[index2]){
                    nums[i]  = nums[index1];
                    nums[index1] =0;
                    index1=index1-1;
                }else{
                    nums[i]  = nums2[index2];
                    nums2[index2] = 0;
                    index2=index2-1;
                }
            }
        }
        return  nums;
    }
}
